<?php

namespace app\site\service\delivery;

use app\model\delivery\PostageTemplate;
use app\site\service\SiteBaseService;
use app\site\service\traits\InstanceTrait;
use think\db\Query;

class PostageTemplateService extends SiteBaseService
{

    use InstanceTrait;

    function initialize()
    {
        $this->model = new PostageTemplate();
    }

    function formatData(array $data): array
    {
        return  $data;
    }

    /**
     * 重新查询函数
     * @return Query
     */
    public function query(): Query
    {
        return $this->makeQuery()->filter(function ($v) {
            // 地区邮费
            $v->regions = PostageTemplateRegionService::instance()->setWhere([
                ['tpl_id', '=', $v->id]
            ])->select();
            // 条件邮费
            $v->conditions = PostageTemplateRegionConditionService::instance()->setWhere([
                ['tpl_id', '=', $v->id]
            ])->select();
            // 不包邮地区
            $v->regionsNo = PostageTemplateRegionNoService::instance()->setWhere([
                ['tpl_id', '=', $v->id]
            ])->find();

        });
    }

}
